#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#define DEVNAME "/dev/hello"
 
 
int main()
{
  char alpha[27];
  int fd,i;
 
  memset(alpha, 0, 27);
  for(i = 0; i < 26; i++)
         alpha[i] = 'A' + i;
 
  fd = open(DEVNAME, O_RDWR);
  if(fd == -1)
  {
         printf("file %s is opening......failure!", DEVNAME);
  }
  else
  {
         printf("file %s is opening......successfully!\nits fd is %d\n", DEVNAME, fd);
  }
 
  getchar();
  printf("write A-Z to kernel......\n");
  write(fd, alpha, 26);
 
  getchar();
  printf("read datas from kernel.......\n");
  read(fd, alpha, 26);
  printf("%s\n", alpha);
 
  getchar();
  close(fd);
 
  return 0;
}
/*  
编译：gcc  main.c  -o main
模块加载并创建结点后（过程参考前面日志），运行./main
结果如下：
file /dev/hello is opening……successfully!
Its fd is 3
(输入回车)
write  A-Z  to  kernel……
(输入回车)
read  datas  from  kernel……
abcdefghijklmnopqrstuvwxyz
(输入回车)
 
 
输入dmesg命令，结果如下：
file open in hello_dev_open……finished!
ABCDEFGHIJKLMNOPQRSTUVWXYZ
file release in hello_dev_open……finished!
*/
